package com.tiankong.product.service.impl;

import com.tiankong.product.entity.SkuInfo;
import com.tiankong.product.mapper.SkuInfoMapper;
import com.tiankong.product.service.SkuImagesService;
import com.tiankong.product.service.SkuInfoService;
import net.youdi.common.base.BaseServiceImpl;
import net.youdi.common.filter.PageFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * sku信息 服务实现类
 * </p>
 *
 * @author scl
 * @since 2021-03-22
 */
@Service
public class SkuInfoServiceImpl extends BaseServiceImpl<SkuInfoMapper, SkuInfo> implements SkuInfoService {

    @Autowired
    private SkuImagesService skuImagesService;
    @Override
    protected void handlePageList(List<SkuInfo> list, PageFilter filter) {
        Map<Long, SkuInfo> map = list.stream().collect(Collectors.toMap(SkuInfo::getSkuId, s -> s));
        skuImagesService.findList(map.keySet()).forEach(i-> {
            try {
                map.get(i.getSkuId()).setImages((List) i.getImages());
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

    }
}
